<template>
    <view style="min-height: 100%; background: #F9F9F9;">
        <view class="common-title help-list-wrapper">
            <text class="common-title-line"/>
            <text>常见问题</text>
        </view>
        <mescroll-uni top="85"  @down="downCallback" @up="upCallback" :down="downOption" :up="upOption"  class="message" @init="mescrollInit">
            <view class="help-list">
                <view v-for="(item, index) in dataList" :key="index" class="help-item common-flex-between" @tap.stop="watchDetail(item)">
                    <text>{{item.helpTitle}}</text>
                    <text class="icon-arrow-right"/>
                </view>
            </view>
        </mescroll-uni>
    </view>
</template>

<script>
    import service from "@/service";
    import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue";
    export default {
        name: "help",
        components: {
            MescrollUni
        },
        data(){
            return{
                dataList: [],
                page: 1,
                limit: 10,
                addlistType: 'list', // 判断是管理列表还是选择地址
                downOption: {
                    auto: false,
                },
                upOption:{
                    use: true, // 是否启用上拉加载; 默认true
                    auto: true, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
                    page: {
                        num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
                        size: 10 // 每页数据的数量,默认10
                    },
                    noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
                    empty: {
                        icon: 'https://img.thumbrary.com/empty.png',
                        tip: '暂无数据'
                    },
                    offset: 130,
                    textNoMore:'我是有底线的 >_<'
                },
                mescroll: null
            }
        },
        methods: {
            mescrollInit(mescroll) {
                this.mescroll = mescroll;
            },
            downCallback(mescroll){
                this.dataList = [];
                this.page = 1;
                mescroll.resetUpScroll();
            },
            upCallback(mescroll){
                this.page = mescroll.num;
                this.getHelpList();
            },
            watchDetail(item){
                uni.navigateTo({
                    url: `./help-detail?helpId=${item.helpId}`
                });
            },
            getHelpList(){
                uni.showLoading({
                    title: '加载中',
                });
                let params = {
                    page: this.page,
                    limit: this.limit
                }
                service.mineService.getHelpList({
                    data: params,
                    success: res => {
                        uni.hideLoading();
                        if (res.code === 200) {
                            let data = res.result.data || [];
                            this.page > 1 ? this.dataList.push(...data) : this.dataList = data;
                            this.mescroll && this.mescroll.endBySize(data.length, res.result.num);
                        } else {
                            uni.showToast({
                                title: `${res.resultMsg}`,
                                duration: 2500,
                                icon: 'none'
                            });
                        }
                    },
                    fail: ()=>{
                        uni.hideLoading();
                    }
                });
            }
        }
    }
</script>

<style scoped lang="scss">
    .help-list-wrapper{
        padding-left: 30rpx;
        background: #F9F9F9;
    }
    .help-list{
        .help-item{
            border-bottom: 1rpx solid #E5E5E5;
            padding: 35rpx 30rpx;
            background: #ffffff;
        }
    }
</style>